#pragma once

#include "StructuralFeature.h"


namespace uml {

const bool StructuralFeature::isReadOnly_default_ = false;
StructuralFeature::StructuralFeature(const QString& umlType)
    : Feature(umlType) {}

void StructuralFeature::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    MultiplicityElement::fromJson(json, errorList);
    TypedElement::fromJson(json, errorList);
    Feature::fromJson(json, errorList);
    isReadOnly_ = json.value("isReadOnly").toBool(isReadOnly_default_);
}

void StructuralFeature::toJson(QJsonObject& json) {
    MultiplicityElement::toJson(json);
    TypedElement::toJson(json);
    Feature::toJson(json);
    if (isReadOnly_ != isReadOnly_default_) {
        json.insert("isReadOnly", isReadOnly_);
    }
}

/// <summary>
/// isReadOnly getter
/// If isReadOnly is true, the StructuralFeature may not be written to after
/// initialization.
/// </summary>
bool StructuralFeature::isReadOnly() const {
    return isReadOnly_;
}

/// <summary>
/// isReadOnly setter
/// If isReadOnly is true, the StructuralFeature may not be written to after
/// initialization.
/// </summary>
void StructuralFeature::setIsReadOnly(bool value) {
    isReadOnly_ = value;
}

} // namespace uml
